package com.atguigu.juc.chap10;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class CompletableFutureDemo04 {

    public static void main(String[] args) {

        // 1、创建线程池对象
        ExecutorService threadPool = Executors.newFixedThreadPool(5);

        // 2、链式调用执行多个任务
        CompletableFuture.supplyAsync(() -> {
                    System.out.println(Thread.currentThread().getName() + "1");
                    return "prev task result";
                }, threadPool)
                // 封装后续任务，并接收前面任务的返回值
                .thenAccept((String prevTaskResult) -> {
                    System.out.println(Thread.currentThread().getName() + " 2 prevTaskResult = " + prevTaskResult);
                });

        // 3、关闭线程池
        threadPool.shutdown();
    }
}